genetic algorithm from scratch